#ifndef STACKTOQUEUE_H
#define STACKTOQUEUE_H

#include "Queue.h"
#include "LinkStack.h"
#include "Exception.h"

namespace DSLib
{
template <typename T>
class StackToQueue : public Queue<T>
{
protected:
	mutable LinkStack<T> m_stackin;
	mutable LinkStack<T> m_stackout;

	void move() const
	{
		if (m_stackout.size() == 0)
		{
			while (m_stackin.size() > 0)
			{
				m_stackout.push(m_stackin.top());
				m_stackin.pop();
			}
		}
	}
public:
	void add(const T& e)
	{
		m_stackin.push(e);
	}

	void remove()
	{
		move();

		if (m_stackout.size() > 0)
		{
			m_stackout.pop();
		}
		else
		{
			THROW_EXCEPTION(InvaildParameterException, "no element to remove!");
		}
	}

	T front() const
	{
		move();
		if (m_stackout.size() > 0)
		{
			return m_stackout.top();
		}
		else
		{
			THROW_EXCEPTION(InvaildParameterException, "no element to remove!");
		}
	}

	void clear()
	{
		m_stackin.clear();
		m_stackout.clear();
	}

	int length() const
	{
		return m_stackin.size() + m_stackout.size();
	}
};

}

#endif